/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package library;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.sql.*;
import java.util.ArrayList;
import javax.swing.JScrollPane;
import javax.swing.JTable;

/**
 *
 * @author Administrator
 */
public class libraryPanel extends javax.swing.JPanel {

    /**
     * Creates new form libraryPanel
     */
    ArrayList<Object[]> data = new ArrayList<Object[]>();
    private JScrollPane scroll_paylist;
    private Object panel_paylist;
    public libraryPanel() {
        initComponents();
        
        try
        {
            
            String dbUrl = "jdbc:mysql://localhost/collegeaccountant";
            String dbClass = "com.mysql.jdbc.Driver";
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn=DriverManager.getConnection(dbUrl,"root","mysql");
            System.err.println("Connected!!!!");
            
            String[] columnNames = {"StudentID",
                    "RegistrationFee",
                    "Fine",
                    "LibrarianID","Book_Magazine_Ordered","Vendor","CostPerPrice","Qty"
                   };

    ResultSet rs = null;
    Statement sql= null;
   
    String query="SELECT StudentID,RegistrationFee, Fine,LibrarianID,Book_Magazine_Ordered,Vendor,CostPerPrice, Qty  FROM library;";
    sql = conn.createStatement();
    sql.executeQuery(query);
    rs = sql.getResultSet();
    
    while(rs.next()){
                Object[] row = new Object[]{
                rs.getString(1), 
                rs.getFloat(2), 
                rs.getFloat(3),
                rs.getString(4),
                rs.getInt(5),
                rs.getString(6),
                rs.getFloat(7),
                rs.getInt(8)};
                //rs.getDate(9),
                //rs.getDate(10)};
                data.add(row);
                 System.err.println("table values!!!!"+rs.next());
            }
    
    Object[][] realData = data.toArray(new Object[data.size()][]);
    tableLibrary= new JTable(realData, columnNames);
    scroll_paylist= new JScrollPane(tableLibrary);        
    tableLibrary.setPreferredScrollableViewportSize(new Dimension(800, 200));
    tableLibrary.setFillsViewportHeight(true);
     System.err.println("code executed!!!!");
        }
        catch (Exception e)
        {
            System.err.println("Not Connected!!!!"+e.getMessage());
             
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        libraryJFrame = new javax.swing.JInternalFrame();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableLibrary = new javax.swing.JTable();

        libraryJFrame.setVisible(true);

        tableLibrary.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tableLibrary);

        javax.swing.GroupLayout libraryJFrameLayout = new javax.swing.GroupLayout(libraryJFrame.getContentPane());
        libraryJFrame.getContentPane().setLayout(libraryJFrameLayout);
        libraryJFrameLayout.setHorizontalGroup(
            libraryJFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, libraryJFrameLayout.createSequentialGroup()
                .addContainerGap(23, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        libraryJFrameLayout.setVerticalGroup(
            libraryJFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(libraryJFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(80, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(libraryJFrame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(391, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(libraryJFrame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(139, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JInternalFrame libraryJFrame;
    private javax.swing.JTable tableLibrary;
    // End of variables declaration//GEN-END:variables
}
